<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cash extends CI_Controller {
	
	function submit(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			$this->load->model('User_model', 'user');
			$this->load->model('Account_bank_model', 'bank');
			$this->load->model('Account_model', 'account');
			$this->load->model('Accountlog_model', 'accountlog');
			
			$data['user'] = $this->user->get_by_uid($user['user_id']);
			$data['bank_list'] = $this->bank->arrays('var_account_bank');
			$data['account'] = $this->account->get_account($user['user_id']);
			$data['cash_fee'] = $this->accountlog->cash_fee($user['user_id']);
			$data['cash_fee'] = min($data['cash_fee'],$data['account']['use_money']);
			
			//****** by liub 20141213  获取银行账户
			$bankno  = $this->input->post('bankno');
			$_bank_where = Array(id=>$bankno,user_id=>$user['user_id']);
			$data['bank'] =$this->bank->get_one($_bank_where);
			//**************** end
			
			if($data['user']['real_status'] != 1){
				$ret['msg'] = '尚未实名认证';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/zhs_mobile/ucenter.html";
				$this->load->view('zhs_mobile/msg',$ret);
			}elseif($data['user']['paypassword'] == ''){
				$ret['msg'] = '尚未设置交易密码';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/zhs_mobile/ucenter.html";
				$this->load->view('zhs_mobile/msg',$ret);
			}elseif (!isset($data['bank'])){
				$ret['msg'] = '未查询到相关银行账户信息';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/zhs_mobile/ucenter.html";
				$this->load->view('zhs_mobile/msg',$ret);
			}else{
				$paypwd = $this->input->post('paypwd');
				$money  = $this->input->post('money');
				if(!is_numeric($money)){
					$ret['msg'] = '无效的金额';
					$ret['url_title'] = '返回';
					$ret['url_next']="/zhs_mobile/cash/submit.html";
					$this->load->view('zhs_mobile/msg',$ret);
					return 0;
				}else{
					$money = round($money,2);
					if($money < 50 || $money > 500000){
						$ret['msg'] = '单笔提现金额超出范围(50-500000)';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash/submit.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}elseif(md5(md5($paypwd)) != $data['user']['paypassword']){
						$ret['msg'] = '交易密码不正确';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash/submit.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}elseif ($data['account']['use_money'] < $money){
						$ret['msg'] = '可用余额不足';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash/submit.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}else{
						
						//15天之内的充值金额提现需要收手续费 0.01收取
						$dont_moeny = $this->accountlog->donnot_mention_15($user['user_id']);
						$this->load->model('Borrow_model');
						$invite_total = $this->Borrow_model->tender_total($user['user_id']);//正在理财中金额
						if(!isset($invite_total)) $invite_total = 0;
						$use_money = ($account_result['use_money'] + $invite_total) - $money;
						$use_money = round($use_money,2);
						$dont_moeny = round($dont_moeny,2);
						
						
						$time = time();
						$ip = $this->input->ip_address();
						$fee = 0;
						
						if($data['user']['is_loan']==0 && $use_money < $dont_moeny){
							$cha = $dont_moeny-$use_money;
							$cha = min($cha,$money);
							$fee = sprintf("%.2f", ($cha*0.005*100)/100);
						}
						$this->db->trans_strict(FALSE);
						$this->db->trans_begin();//事务开始
						//添加提现表记录
						$setArr = array(
							'user_id' => $user['user_id'],
							'fstatus' => '0',
							'account' => $data['bank']['account'],
							'bank' => $data['bank']['bank'],
							'branch' => $data['bank']['branch'],
							'province' => $data['bank']['province'],
							'city' => $data['bank']['city'],
							'total' => $money,
							'credited' => $money - $fee,
							'fee' =>$fee,
							'add_time' => $time,
							'addip' => $ip
						);
						
						$this->load->model('Accountcash_model', 'cash');
						$ret = $this->cash->add($setArr);
						if($ret > 0){
							$log = array(
								'user_id' => $user['user_id'],
								'ftype' => CASH_FROST,
								'money' => $money,
								'total' => $data['account']['total'],
								'use_money' => $data['account']['use_money']-$money,
								'no_use_money' => $data['account']['no_use_money']+$money,
								'collection' => $data['account']['collection'],
								'red_money' => $data['account']['red_money'],
								'to_user' => 0,
								'add_time' => $time,
								'addip' => $ip,
								'remark' => "提现冻结"
							);
							$ret = $this->account->addlog($log);
						}
						if($this->db->trans_status() === TRUE){
							$this->db->trans_commit();
							$ret1['msg'] = '提现申请已提交，请等待审核';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/zhs_mobile/ucenter.html";
							$this->load->view('zhs_mobile/msg',$ret1);
						}else{
							$this->db->trans_rollback();
							$ret1['msg'] = '提现失败，请重试';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/zhs_mobile/cash/submit.html";
							$this->load->view('zhs_mobile/msg',$ret1);
						}
					}
				}
			}
		}else{
			header('Location: /zhs_mobile/login/index.html');
		}
	}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cash extends CI_Controller {
    
	function submit(){
		$user = $this->session->userdata('rsh_user');
		if(isset($user['user_id']) && $user['user_id'] > 0){
			$this->load->model('User_model', 'user');
			$this->load->model('Account_bank_model', 'bank');
			$this->load->model('Account_model', 'account');
			$this->load->model('Accountlog_model', 'accountlog');
			
			$data['user'] = $this->user->get_by_uid($user['user_id']);
			$data['bank_list'] = $this->bank->arrays('var_account_bank');
			$data['account'] = $this->account->get_account($user['user_id']);
			$data['cash_fee'] = $this->accountlog->cash_fee($user['user_id']);
			$data['cash_fee'] = min($data['cash_fee'],$data['account']['use_money']);
			
			//****** by liub 20141213  获取银行账户
			$bankno  = $this->input->post('bankno');
			$_bank_where = Array(id=>$bankno,user_id=>$user['user_id']);
			$data['bank'] =$this->bank->get_one($_bank_where);
			//**************** end
			
			if($data['user']['real_status'] != 1){
				$ret['msg'] = '尚未实名认证';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/zhs_mobile/ucenter.html";
				$this->load->view('zhs_mobile/msg',$ret);
			}elseif($data['user']['paypassword'] == ''){
				$ret['msg'] = '尚未设置交易密码';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/zhs_mobile/ucenter.html";
				$this->load->view('zhs_mobile/msg',$ret);
			}elseif (!isset($data['bank'])){
				$ret['msg'] = '未查询到相关银行账户信息';
				$ret['url_title'] = '返回用户中心';
				$ret['url_next']="/zhs_mobile/ucenter.html";
				$this->load->view('zhs_mobile/msg',$ret);
			}else{
				$paypwd = $this->input->post('paypwd');
				$money  = $this->input->post('money');
				if(!is_numeric($money)){
					$ret['msg'] = '无效的金额';
					$ret['url_title'] = '返回';
					$ret['url_next']="/zhs_mobile/cash/submit.html";
					$this->load->view('zhs_mobile/msg',$ret);
					return 0;
				}else{
					$money = round($money,2);
					if($money < 50 || $money > 500000){
						$ret['msg'] = '单笔提现金额超出范围(50-500000)';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash/submit.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}elseif(md5(md5($paypwd)) != $data['user']['paypassword']){
						$ret['msg'] = '交易密码不正确';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash/submit.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}elseif ($data['account']['use_money'] < $money){
						$ret['msg'] = '可用余额不足';
						$ret['url_title'] = '返回';
						$ret['url_next']="/zhs_mobile/cash/submit.html";
						$this->load->view('zhs_mobile/msg',$ret);
					}else{
						
						//15天之内的充值金额提现需要收手续费 0.01收取
						$dont_moeny = $this->accountlog->donnot_mention_15($user['user_id']);
						$this->load->model('Borrow_model');
						$invite_total = $this->Borrow_model->tender_total($user['user_id']);//正在理财中金额
						if(!isset($invite_total)) $invite_total = 0;
						$use_money = ($account_result['use_money'] + $invite_total) - $money;
						$use_money = round($use_money,2);
						$dont_moeny = round($dont_moeny,2);
						
						
						$time = time();
						$ip = $this->input->ip_address();
						$fee = 0;
						
						if($data['user']['is_loan']==0 && $use_money < $dont_moeny){
							$cha = $dont_moeny-$use_money;
							$cha = min($cha,$money);
							$fee = sprintf("%.2f", ($cha*0.005*100)/100);
						}
						$this->db->trans_strict(FALSE);
						$this->db->trans_begin();//事务开始
						//添加提现表记录
						$setArr = array(
							'user_id' => $user['user_id'],
							'fstatus' => '0',
							'account' => $data['bank']['account'],
							'bank' => $data['bank']['bank'],
							'branch' => $data['bank']['branch'],
							'province' => $data['bank']['province'],
							'city' => $data['bank']['city'],
							'total' => $money,
							'credited' => $money - $fee,
							'fee' =>$fee,
							'add_time' => $time,
							'addip' => $ip
						);
						
						$this->load->model('Accountcash_model', 'cash');
						$ret = $this->cash->add($setArr);
						if($ret > 0){
							$log = array(
								'user_id' => $user['user_id'],
								'ftype' => CASH_FROST,
								'money' => $money,
								'total' => $data['account']['total'],
								'use_money' => $data['account']['use_money']-$money,
								'no_use_money' => $data['account']['no_use_money']+$money,
								'collection' => $data['account']['collection'],
								'red_money' => $data['account']['red_money'],
								'to_user' => 0,
								'add_time' => $time,
								'addip' => $ip,
								'remark' => "提现冻结"
							);
							$ret = $this->account->addlog($log);
						}
						if($this->db->trans_status() === TRUE){
							$this->db->trans_commit();
							$ret1['msg'] = '提现申请已提交，请等待审核';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/zhs_mobile/ucenter.html";
							$this->load->view('zhs_mobile/msg',$ret1);
						}else{
							$this->db->trans_rollback();
							$ret1['msg'] = '提现失败，请重试';
							$ret1['url_title'] = '返回';
							$ret1['url_next']="/zhs_mobile/cash/submit.html";
							$this->load->view('zhs_mobile/msg',$ret1);
						}
					}
				}
			}
		}else{
			header('Location: /zhs_mobile/login/index.html');
		}
	}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}